package com.github.wxpay.sdk.test;

import com.github.wxpay.sdk.IWXPayDomain;
import com.github.wxpay.sdk.WXPayConfig;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Description:微信配置
 * Author:THP
 * Date:2018/05/24 09:41
 */
public class WXPayConfigImpl extends WXPayConfig {
    private byte[] certData;
    private static WXPayConfigImpl INSTANCE;

    public final static String NOTIFY_URL = "http://***/wx-pay/callback";
//    public final static String NOTIFY_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";

    private WXPayConfigImpl() throws Exception {
        //获取证书
        File file = new File("C://Users/Administrator/Downloads/java_sdk_v3.0.9/path/to/apiclient_cert.p12");
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static WXPayConfigImpl getInstance() throws Exception {
        if (INSTANCE == null) {
            synchronized (WXPayConfigImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WXPayConfigImpl();
                }
            }
        }
        return INSTANCE;
    }

    public String getAppID() {
        return "wx8888888888888888";
    }


    public String getMchID() {
        return "12888888";
    }


    public String getKey() {
        return "88888888888888888888888888888888";
    }


    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 6000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }


//    @Override
//    protected IWXPayDomain getWXPayDomain() {
//        return null;
//    }

    public IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

//    @Override
//    public int getReportWorkerNum() {
//        return 1;
//    }
//
//    @Override
//    public int getReportBatchSize() {
//        return 2;
//    }
}
